package part03_工厂模式.p05_反射之工厂设计模式;

import java.lang.reflect.InvocationTargetException;

/**
 * @ClassName: Factory
 * @Author: AllenSun
 * @Date: 2020/3/29 16:12
 */
public class Factory {
    public static Fruit getInsance(String className){
        Fruit fruit = null;
        try {
            fruit = (Fruit) Class.forName(className).getDeclaredConstructor().newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        return fruit;
    }
}
